package com.wtwd.campus.receiver;

import com.wtwd.campus.entity.MqDeviceImeid;
import com.wtwd.campus.entity.MqLocationData;
import com.wtwd.campus.service.IRMFeignClientService;
import com.wtwd.campus.service.InjectFeignService;
import com.wtwd.campus.utils.LocationUtils;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

public class DeviceImeIdReceiver implements Receiver {
    @Autowired
    private IRMFeignClientService irmFeignClientService;

    @Override
    public String parseMessage(String data) {
        // *WT,866248050395985,GETIMEID,164931,164932,866248050395985,A,2250.2243,N,11391.6211,E,0.14,332,020621,FFFFDFFF
        String[] split = data.split(",");
        String imei=split[1];
        String messageType = split[2];
        String commandNumber = split[3];
        String deviceTime = split[4];
        String imeid = split[5];//设备上报的imeid
        String lat = split[7];
        String lng = split[9];
        String speed = split[11];
        String orientation = split[12];
        String date = split[13];
        String deviceStatus = split[14];
        MqLocationData mqLocationData = new MqLocationData();
        mqLocationData.setOrientation(Integer.parseInt(orientation));
        mqLocationData.setSpeed(Double.parseDouble(speed));
        List<Double> latlng = LocationUtils.transiformLatAndLng(lng,lat);
        mqLocationData.setLatitude(latlng.get(1));
        mqLocationData.setLongitude(latlng.get(0));
        MqDeviceImeid mqDeviceImeid = new MqDeviceImeid();
        mqDeviceImeid.setCommandNumber(commandNumber);
        mqDeviceImeid.setDeviceDate(date);
        mqDeviceImeid.setDeviceStatus(deviceStatus);
        mqDeviceImeid.setDeviceTime(deviceTime);
        mqDeviceImeid.setImei(imei);
        mqDeviceImeid.setMqLocationData(mqLocationData);
        mqDeviceImeid.setUploadImeiId(imeid);
        // 远程调用
        InjectFeignService.getIrmFeignClientService().queryImeidResponse(mqDeviceImeid);
        return imei;
    }
}
